package com.appfront;

import android.content.Context;
import android.content.SharedPreferences;

import com.appfront.debug.App;

/**
 * Created by kook on 2018/9/16.
 */
public class TestproSetup {
    public static String usrID = "";
    static int currentPlan = 1;                     //当前测试方案：方案一
    /* 曲线显示效果 */
    static boolean isForceRawShow = false;          // 显示原采集线
    static boolean isForceCubicShwo = true;         // 显示滤波后采集线
    static int cubicNums = 10;                      //  滤波点数
    static boolean cubicNomax = true;              // 去除最大/最小值
    /* 测试参数基础配置 */
    static float forceBase = (float)4.5;            //测试力基准值
    static int   forceInit = 0;                     //测试力初始值
    public static float forceScaleMax = (float)0.9;        // 峰值力的比例
    /* 专业测试输入参数 */
    public static boolean isMale = false;
    public static int userAge = 20;
    public static int userHeight = 170;
    public static int userWeight = 60;

    /* 测试参数扩展配置 */
    static String []plan_str = new String[]{"处方一", "处方二", "处方三", "处方四", "处方五",
            "处方六", "处方七", "处方八", "处方九", "处方十"};
    static String []lines_str = new String[]{"Peach:桃红色线", "Orange:橙色线", "Lime:绿色线", "Blueberry:蓝色线", "Plum:紫色线", "Gray:灰色线"};
    private static int [] testGroup     = new int[]{1,  1,  1,  1,  1,  1,  1,  1,  1,  1 };    //测试组数
    private static int [] testFreqs     = new int[]{6, 6, 6, 6, 6, 6, 6, 6, 6, 6};    //单组次数
    private static int [] testGroupTime = new int[]{45, 45, 45, 45, 45, 45, 45, 45, 45, 45};    //组间休息时间
    private static int [] testFreqsTime = new int[]{90, 90, 90, 90, 90, 90, 90, 90, 90, 90};    //单次之间最长休息时间
    private static int [] peakForceTime = new int[]{10, 10, 10, 10, 10, 10, 10, 10, 10, 10};    //峰值力持续时间
    private static int [] isStartForce  = new int[]{0,  0,  0,  0,  0,  0,  0,  0,  0,  0 };    //是否采用弹力带起始值方案
    private static int [] startForceN   = new int[]{15, 15, 15, 15, 15, 15, 15, 15, 15, 15};    //拉动弹力带起始值

    /* 弹力带参数 */
    private static int [] curLines = new int[]{6, 6, 6, 6, 6, 6, 6, 6, 6, 6};    //当前的弹力带：1~6
    public final static float line_raw_len = (float) 1.2;   //m
    public final static double[] line_scale  = new double[]{0.25, 0.5,  0.75,  1.0,   1.25,  1.5,   1.75,  2.0,   2.25,  2.5,   2.75,  3.0};
    public final static double[] line_peach  = new double[]{2.11, 3.65, 4.69,  5.61,  6.34,  7.04,  7.72,  8.36,  9.09,  9.68,  10.27, 11.07};
    public final static double[] line_orange = new double[]{3.10, 5.46, 6.78,  8.14,  9.35,  10.34, 11.44, 12.39, 13.51, 14.54, 15.55, 16.63};
    public final static double[] line_green  = new double[]{3.63, 6.14, 7.83,  9.35,  10.56, 11.66, 12.78, 13.79, 15.00, 15.97, 16.98, 18.26};
    public final static double[] line_blue   = new double[]{4.20, 7.02, 8.76,  10.34, 11.75, 12.96, 14.08, 15.16, 16.61, 17.49, 18.59, 19.73};
    public final static double[] line_plum   = new double[]{4.53, 7.59, 9.79,  11.75, 13.29, 14.89, 16.48, 17.91, 19.69, 21.03, 22.53, 24.29};
    public final static double[] line_gray   = new double[]{5.39, 8.84, 11.29, 13.62, 15.49, 17.05, 18.85, 20.39, 22.44, 23.80, 25.43, 27.24};

    static String getCurPlanName(){
        return plan_str[currentPlan-1];
    }
    static int getCurGroup(){
        return testGroup[currentPlan-1];
    }
    public static int getCurFreqs(){
        return testFreqs[currentPlan-1];
    }
    static int getCurGroupTime(){
        return testGroupTime[currentPlan-1];
    }
    static int getCurFreqsTime(){
        return testFreqsTime[currentPlan-1];
    }
    static int getCurPeakForceTime() {return peakForceTime[currentPlan-1];}
    static boolean getIsStartForce() {
        if(0 != isStartForce[currentPlan-1]){
            return true;
        }else{
            return false;
        }
    }
    static int getStartForceN(){
        return startForceN[currentPlan-1];
    }
    public static int getCurLines() {
        int lines = curLines[currentPlan-1];
        if(lines < 1)   lines = 1;
        if(lines > 6)   lines = 6;
        return  lines;
    }

    static void setCurPlanName(String planName){
        plan_str[currentPlan-1] = planName;
    }
    static void setCurGroup(int curGroup){
        testGroup[currentPlan-1] = curGroup;
    }
    static void setCurFreqs(int curFreqs){
        testFreqs[currentPlan-1] = curFreqs;
    }
    static void setCurGroupTime(int curGroupTime){
        testGroupTime[currentPlan-1] = curGroupTime;
    }
    static void setCurFreqsTime(int curFreqsTime){
        testFreqsTime[currentPlan-1] = curFreqsTime;
    }
    static void setCurPeakForceTime(int curPeakForceTime) { peakForceTime[currentPlan-1] = curPeakForceTime; }
    static void setIsStartForce(boolean isStartN){
        if(isStartN)    isStartForce[currentPlan-1] = 1;
        else            isStartForce[currentPlan-1] = 0;
    }
    static void setStartForceN(int forceN){
        startForceN[currentPlan-1] = forceN;
    }
    static void setCurLines(int lines) {
        if(lines < 1)   lines = 1;
        if(lines > 6)   lines = 6;
        curLines[currentPlan-1] = lines;
    }

    public static void StoreSetup(){
        if(currentPlan < 1 || currentPlan > 10)
            return;
        Context context = App.getContext();
        SharedPreferences sharedPreferences = context.getSharedPreferences("testConfig", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("testGroup"     + currentPlan,  testGroup[currentPlan-1]);
        editor.putInt("testFreqs"     + currentPlan,  testFreqs[currentPlan-1]);
        editor.putInt("testGroupTime" + currentPlan,  testGroupTime[currentPlan-1]);
        editor.putInt("testFreqsTime" + currentPlan,  testFreqsTime[currentPlan-1]);
        editor.putInt("peakForceTime" + currentPlan,  peakForceTime[currentPlan-1]);
        editor.putInt("curLines" + currentPlan, curLines[currentPlan-1]);
        editor.putInt("isStartForce" + currentPlan, isStartForce[currentPlan-1]);
        editor.putInt("startForceN" + currentPlan, startForceN[currentPlan-1]);
        editor.commit();//提交修改
    }

    public static void LoadSetup(){
        if(currentPlan < 1 || currentPlan > 10)
            return;
        Context context = App.getContext();
        SharedPreferences sharedPreferences = context.getSharedPreferences("testConfig", Context.MODE_PRIVATE);
        testGroup[currentPlan-1]     = sharedPreferences.getInt("testGroup" + currentPlan, 1);
        testFreqs[currentPlan-1]     = sharedPreferences.getInt("testFreqs" + currentPlan, 6);
        testGroupTime[currentPlan-1] = sharedPreferences.getInt("testGroupTime" + currentPlan, 45);
        testFreqsTime[currentPlan-1] = sharedPreferences.getInt("testFreqsTime" + currentPlan, 90);
        peakForceTime[currentPlan-1] = sharedPreferences.getInt("peakForceTime" + currentPlan, 10);
        curLines[currentPlan-1] = sharedPreferences.getInt("curLines" + currentPlan, 6);
        isStartForce[currentPlan-1] = sharedPreferences.getInt("isStartForce" + currentPlan, 0);
        startForceN[currentPlan-1] = sharedPreferences.getInt("startForceN", 15);
    }

    public static void LoadPlanName(){
        Context context = App.getContext();
        SharedPreferences sharedPreferences = context.getSharedPreferences("testConfig", Context.MODE_PRIVATE);
        for(int i=0; i<10; i++){
            plan_str[i] = sharedPreferences.getString("planName" + i+1, plan_str[i]);
        }
    }
}
